<script>
    initDialog("#new_tab","Add new tab");
    initDialog("#tab_cats","Categories");
    initDialog("#new_tab_cat","Add category");
    initDialog("#edit_tab","Update");
    function updateTab(tid){
        //openDialog('#edit_tab');
        var newVal=prompt("Enter the new Cat");
        if(newVal.length>0){
            window.location="<?php echo base_url(); ?>index.php?/admin_settings/updateTab/"+tid+"/"+newVal;
        }
    }
    function searchTabs(){
        $("#loadingTab").show();
        var cat=$("select#cat").val();
        $("#tabsPage").load("<?= base_url(); ?>index.php?/admin_settings/tabs/"+cat);
    }
    function clearSearch(){
        $("#loadingTab").show();
        $("#tabsPage").load("<?= base_url(); ?>index.php?/admin_settings/tabs");
    }
</script>
<div id="tabsPage">
    <div class="post">
        <h2 class="title">Tabs</h2>
        <a href='<?php echo base_url(); ?>index.php?/admin_settings/sortTabs/'>SORT A-Z</a>
        <div class="entry">

            <input type="button" value="Add new" onclick="openDialog('#new_tab')"/>
            <input type="button" value="Categories" onclick="openDialog('#tab_cats')"/>
            <select name="cat" onchange="searchTabs()" id="cat">
                <option value="0">Filter by category</option>
                <?php foreach ($cats as $row) {
                ?>
                <option value="<?= $row['tid'] ?>" <?php if($row['tid']==$currentCat){?>selected="selected"<?php } ?> ><?= $row['name'] ?></option>
                <?php } ?>
            </select>
            <input type="button"  value="Clear search" onclick="clearSearch()"/>

            <img src="<?= base_url(); ?>images/loading.gif" alt="Loading.." style="display: none;" id="loadingTab"/>

            <div id="tab_result" style="display: none" >
            </div>
            <div id="tab_cats">
                <?= $tab_cats ?>
                <input type="button" value="Add new Category" onclick="openDialog('#new_tab_cat')"/>
                <p></p>
            </div>
            <div id="new_tab_cat">
                <?php $data['id'] = "tab_cat_form" ?>
                <?= form_open_multipart('admin_settings/saveTabcat', $data); ?>
                <table>
                    <tr class="darker"><td class="half">Name</td><td><input type="text" class="wide" name="name"  /></td> </tr>
                    <tr><td colspan="2" style="text-align: right">
                            <input type="submit" value="Submit" />
                        </td></tr>
                </table>
                </form>
            </div>

            <!--a href="" id="hide3" >Hide</a> <a href="" id="show3" >Show</a-->
            <div id="new_tab" style="display: none;margin-bottom: 10px;">
                <?php $data['id'] = "tab_edit_form" ?>
                <?= form_open_multipart('admin_settings/saveTab', $data); ?>
                <table>
                    <tr class="darker"><td class="half">Name</td><td><input type="text" class="wide" name="name" id="edit_name" id="ddd" /></td> </tr>
                    <tr  class="lighter"><td>URL</td><td><input type="text"  class="wide" name="url" /></td> </tr>
                    <tr  class="darker"><td>Category</td><td>
                            <select name="cat">
                                <?php foreach ($cats as $row) {
                                ?>
                                    <option value="<?= $row['tid'] ?>"><?= $row['name'] ?></option>
                                <?php } ?>
                            </select>
                        </td> </tr>
                    <tr><td colspan="2" style="text-align: right">
                            <input type="submit" value="Submit" />
                        </td></tr>
                </table>
                </form>
            </div>
            <div id="edit_tab">
                <?php $data['id'] = "tab_form" ?>
                <?= form_open_multipart('admin_settings/updateTab', $data); ?>
                                <table>
                                    <tr class="darker"><td class="half">Name</td><td><input type="text" class="wide" name="name"  /></td> </tr>
                                    <tr  class="lighter"><td>URL</td><td><input type="text"  class="wide" name="url" /></td> </tr>
                                    <tr  class="darker"><td>Category</td><td>
                                            <select name="cat">
                                <?php foreach ($cats as $row) {
                                ?>
                                    <option value="<?= $row['tid'] ?>"><?= $row['name'] ?></option>
                                <?php } ?>
                            </select>
                        </td> </tr>
                    <tr><td colspan="2" style="text-align: right">
                            <input type="submit" value="Update" />
                        </td></tr>
                </table>
                </form>
            </div>
            <div id="all_tabs">
                <?= $tablet ?>
                <?= $pagina ?>
            </div>

        </div>
    </div>
</div>